<!-- 检查报告 -->
<template>
	<view class="inspection-report">
		<view class="tabs-wrapper">
			<liuyuno-tabs :tabData="tabsData" :defaultIndex="1" @tabClick="tabClick" />
		</view>

		<view style="padding: 10px;">
			<view class="date-select-wrapper">
				<uni-datetime-picker v-model="range" type="daterange" @change="dateRangeChangeHandler" />
			</view>

			<view v-if="currentTabIndex == 0">
				<view class="list-wrapper">
					<view class="item" v-for="item in dataList1" @click="goToJyDetail(item)">
						<p class="time">开单日期：{{item.ReportTime}}</p>
						<uni-tag class="float-right" :circle="true" :text="'可打印次数:' + item.PrintNum" type="default"
							size="mini" />
						<div class="clearfix"></div>
						<p>开单医生：{{item.Doctor}}</p>
						<p>开单科室：{{item.Department}}</p>
						<p>报告类别：{{item.ReportClass}}</p>
						<p>临床诊断：{{item.ClinicDiag}}</p>
					</view>
				</view>
				<u-empty v-if="dataList1.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/car.png">
				</u-empty>
			</view>

			<view v-if="currentTabIndex == 1">
				<view class="list-wrapper">
					<view class="item" v-for="item in dataList2" @click="goToJcDetail(item)">
						<p class="time">开单日期：{{item.ReportTime}}</p>
						<uni-tag class="float-right" :circle="true" :text="'可打印次数:' + item.PrintNum" type="default"
							size="mini" />
						<div class="clearfix"></div>
						<p>开单医生：{{item.Doctor}}</p>
						<p>开单科室：{{item.Department}}</p>
						<p>报告类别：{{item.ReportClass}}</p>
					</view>
				</view>
				<u-empty v-if="dataList2.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/car.png">
				</u-empty>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabsData: [{
						state: 1,
						name: '检验报告'
					},
					{
						state: 2,
						name: '检查报告'
					}
				],
				currentTabIndex: 0,
				range: [],
				dataList1: [],
				dataList2: []
			}
		},
		onLoad() {
			this.api_examinereport()
		},
		methods: {
			tabClick(val) {
				this.currentTabIndex = val
				if (val == '0') {
					this.api_examinereport()
				} else if (val == '1') {
					this.api_inspectreport()
				}
			},
			
			goToJyDetail(item) {
				uni.navigateTo({
					url: '/pagesB/healthCard/jyDetail?reportno=' + item.ReportId
				})
			},
			
			goToJcDetail(item) {
				uni.navigateTo({
					url: '/pagesB/healthCard/jcDetail?reportno=' + item.ReportId
				})
			},

			dateRangeChangeHandler(e) {
				console.log('dateRangeChangeHandler:', e);
				if (this.currentTabIndex == '0') {
					this.api_examinereport()
				} else if (this.currentTabIndex == '1') {
					this.api_inspectreport()
				}
			},

			api_examinereport() {
				this.dataList1 = []
				let openid = uni.getStorageSync('openid')
				let numcard = uni.getStorageSync('current_user_card').numcard
				if (this.range.length > 0) {
					this.$app._post_form2("apireport.examinereport", {
						"reportid": "0",
						"openid": openid,
						"cardid": numcard,
						// "cardid": '644304',
						"medicaltype": "0",
						"medicalid": "0",
						"pageidx": "1",
						"pagesize": "1000",
						"starttime": this.range[0] + ' 00:00:00',
						"endtime": this.range[1] + ' 23:59:59'
					}, (res) => {
						console.log(res)
						if (res.status == '1' && res.data != 'none') {
							this.dataList1 = res.data
						}
					})
				}
			},

			api_inspectreport() {
				this.dataList2 = []
				let openid = uni.getStorageSync('openid')
				let numcard = uni.getStorageSync('current_user_card').numcard
				if (this.range.length > 0) {
					this.$app._post_form2("apireport.inspectreport", {
						"reportid": "0",
						"openid": openid,
						"cardid": numcard,
						// "cardid": "644304",
						"medicaltype": "0",
						"medicalid": "0",
						"pageidx": "1",
						"pagesize": "10",
						"starttime": this.range[0] + ' 00:00:00',
						"endtime": this.range[1] + ' 23:59:59'
					}, (res) => {
						console.log(res)
						if (res.status == '1' && res.data != 'none') {
							this.dataList2 = res.data
						}
					})
				}
			}
		}
	}
</script>

<style>
	>>>._item._active {
		color: #41C177 !important;
	}

	>>>._underline {
		background-color: #41C177 !important;
	}
</style>

<style scoped lang="scss">
	.tabs-wrapper {
		background-color: #fff;
	}

	.inspection-report {
		width: 100%;
		height: 100%;
		color: #757575;
		box-sizing: border-box;

		.date-select-wrapper {
			margin-bottom: 5px;
		}

		.list-wrapper {

			.item {
				padding: 10px;
				background-color: #fff;
				border-radius: 8px;
				color: #757575;
				font-size: .8rem;
				margin-bottom: 5px;

				p {
					line-height: 25px;
				}

				.time {
					color: #ff9800;
					float: left;
				}
			}
		}
	}
</style>